/**
 * @param {number[]} nums
 * @return {number}
 */
var majorityElement = function(nums) {
  let sort = {},
    len = nums.length / 2
  for (let i = 0; i < nums.length; i++) {
    sort[nums[i]] ? (sort[nums[i]] += 1) : (sort[nums[i]] = 1)
    if (sort[nums[i]] > len) return nums[i]
  }
}

console.log(majorityElement([2, 2, 1, 1, 1, 2, 2]))
